/**
 * Package: IO.Serial
 */

#define SR_5BIT   0x80
#define SR_6BIT   0x82
#define SR_7BIT   0x84
#define SR_8BIT   0x86

#define SR_1STOP  0x00
#define SR_2STOP  0x08

#define SR_NO_PAR     0x00
#define SR_EVEN_PAR   0x20
#define SR_ODD_PAR    0x30

#define SR_BD2400   383    // baudrate    2400bps
#define SR_BD4800   191    // baudrate    4800bps
#define SR_BD9600    95    // baudrate    9600bps
#define SR_BD14400   63    // baudrate   14400bps
#define SR_BD19200   47    // baudrate   19200bps
#define SR_BD28800   31    // baudrate   28800bps
#define SR_BDMIDI    0x8039// baudrate   31250bps MIDI
#define SR_BD38400   23    // baudrate   38400bps
#define SR_BD57600   15    // baudrate   57600bps
#define SR_BD76800   11    // baudrate   76800bps
#define SR_BD115200   7    // baudrate  115200bps
#define SR_BD230400   3    // baudrate  230400bps

/// <summary>The serial interface gets switched off and the corresponding ports can be used otherwise.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
void Serial_Disable         $opc(0x61)(byte serport);

/// <summary>The serial interface gets initialized for usage in interrupt mode. The user has to provide a global variable as a serial buffer. This buffer services as a storage for the data that is sent to the serial interface and is received from it. The size of the buffer must be length of the send buffer plus the length of the receive buffer plus 6 bytes.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
/// <param name="ramaddr">Address of the buffer</param>
/// <param name="recvlen">Size of receive buffer</param>
/// <param name="sendlen">Size of send buffer</param>
/// <param name="par">Interface parameter</param>
/// <param name="divider">Baud rate initialization</param>
void Serial_Init_IRQ        $opc(0x73)(byte serport,byte ramaddr[],byte recvfifolen,byte sendfifolen,byte par,word divider);

/// <summary>In dependency of the info parameter the function returns how many bytes have been received or a written to the send buffer.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
/// <returns>Result in bytes.</returns>
byte Serial_IRQ_Info        $opc(0x74)(byte serport,byte info);

/// <summary>One byte is send to the serial interface.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
void Serial_Write           $opc(0x2E)(byte serport,byte val);

/// <summary>Reads one byte from the serial interface. If is there is no byte available in the serial interface, the function waits until a byte has been received.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
/// <returns>Received byte from the serial interface.</returns>
byte Serial_Read            $opc(0x2F)(byte serport);

/// <summary>The serial interface gets initialized.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
/// <param name="par">Interface parameter</param>
/// <param name="divider">Baud rate initialization</param>
void Serial_Init            $opc(0x30)(byte serport,byte par,word divider);

/// <summary>Reads one byte from the serial interface.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
/// <returns>Received byte from the serial interface. 256 (0x100) if there was no byte available.</returns>
word Serial_ReadExt         $opc(0x31)(byte serport);

/// <summary>All characters of the char array up to the terminating zero are sent to the serial interface.</summary>
/// <param name="serport">Interface number (0 = 1st serial port, 1 = 2nd serial port, ...)</param>
/// <param name="text">Char array.</param>
void Serial_WriteText       $opc(0x56)(byte serport,char text[]);